<?php

if (!defined('TOBBIVM'))
	header('location:/template/notrepassing.php');
/**
 * This file is part of TobbiVMShop.
 *
 * TobbiVMShop is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * TobbiVMShop is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with TobbiVMShop.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Datei: options.class.php
 *
 * Class to edit all options for the articlepage
 *
 * @author Norbert Gebert
 * @copyright Norbert Gebert 25.09.2011
 * @license GPL3
 *
 * @version 0.6b
 * @package Admin
 * @subpackage global
 */
class options
{

	// @var $_id String attribute-id
	private $_id = '';
	// @var $_htmlTextrow array (string) html-code to display Textrowoptions
	private $_htmlTextrow = array();
	// @var $_htmlTextfield array (string) html-code to display Textfieldoptions
	private $_htmlTextfield = array();
	// @var $_htmlTextfield array (string) html-code to display DropDownmenue
	private $_htmlDropDown = array();
	// @var $_htmlTextfield array (string) html-code to display Optionslist
	private $_htmlOptionList = array();

	/**
	 * Initializes the system-variable if still not available. 
	 */
	function __construct($id)
	{
		$this->_id = $id;
		// Get all options for given attribute-id
		db::getInstance()->where('options_attribute_id', $_GET['id']);
		db::getInstance()->orderBy('options_order', 'ASC');
		$optionsList = db::getInstance()->get('options');

		if (db::getInstance()->count <= 0)
			return;

		foreach ($optionsList as $optionRow)
		{
			switch ($optionRow['options_art'])
			{
				case '1': // Textrow
					$this->_getTextRow($optionRow);
					break;
				case '2': // Textfield
					$this->_getTextfield($optionRow);
					break;
				case '3': // Drop-Down
					$this->_getDropDown($optionRow);
					break;
				case '4': // Option-List
					$this->_getOptionList($optionRow);
					break;
			}
		}
	}

	/**
	 * Returns html-code for textrows
	 * @return array Associative array with html-code for textrows
	 */
	public function getTextRows()
	{
		return $this->_htmlTextrow;
	}

	/**
	 * Returns html-code for textfields
	 * @return array Associative array with html-code for textfields
	 */
	public function getTextfields()
	{
		return $this->_htmlTextfield;
	}

	/**
	 * Returns html-code for dropdowns
	 * @return array Associative array with html-code for Dropdownmenues
	 */
	public function getDropDowns()
	{
		return $this->_htmlDropDown;
	}

	/**
	 * Returns html-code for optionlist
	 * @return array Associative array with html-code for optionlist
	 */
	public function getOptions()
	{
		return $this->_htmlOptionList;
	}

	/**
	 * create html-code for a single textrow
	 * @param array $optionRow row from database. Table "options"
	 * @return array Associative array with html-code
	 */
	private function _getTextRow(&$optionRow)
	{
		$this->_htmlTextrow[] = array(
		 'textrowtitelnamex' => _('Textrowtitel') . ': ',
		 'textrowtitelx' => '<input type="text" name="titelx' . $optionRow['options_id'] . '" ' .
		 'id="' . $optionRow['options_id'] . '" ' .
		 'size="' . $optionRow['options_width'] . '" ' .
		 'value="' . $optionRow['options_titel'] . '" />',
		 'textrownamex' => _('Textrow') . ': ',
		 'textrowx' => '<input type="text" name="textx' . $optionRow['options_id'] . '" ' .
		 'id="' . $optionRow['options_id'] . '" ' .
		 'size="' . $optionRow['options_width'] . '" ' .
		 'value="' . $optionRow['options_text'] . '" />',
		 'widthnamex' => _('Width') . ': ',
		 'widthx' => '<input type="text" name="widthx' . $optionRow['options_id'] . '" ' .
		 'id="widthx' . $optionRow['options_id'] . '" ' .
		 'size="5" ' .
		 'value="' . $optionRow['options_width'] . '" />',
		 'positionnamex' => _('Position') . ': ',
		 'positionx' => '<input type="text" name="positionx' . $optionRow['options_id'] . '" ' .
		 'id="positionx' . $optionRow['options_id'] . '" ' .
		 'size="5" ' .
		 'value="' . $optionRow['options_order'] . '" />',
		 'btn_delete' => '<a class="option_delete" href="index2.php?page=article&sub=attribute' .
		 '&id=' . $optionRow['options_attribute_id'] . '&func=options&optid=' .
		 $optionRow['options_id'] . '&subfunc=delete">' . _('Delete this option') . '</a>',
		 'btn_save' => '<input type="submit" name="submit" id="save" value="' .
		 _('Save changes') . '" />',
		 'texttitelHelp' => help('texttitel', 'article/option'),
		 'textrowHelp' => help('textrow', 'article/option'),
		 'widthHelp' => help('width', 'article/option'),
		 'positionHelp' => help('position', 'article/option'));
	}

	/**
	 * create html-code for a single textfield
	 * @param array $optionRow row from database. Table options 
	 * @return array Associative array with html-code
	 */
	private function _getTextfield(&$optionRow)
	{
		$this->_htmlTextfield[] = array(
		 'textfieldtitelnamex' => _('Textfieldtitel') . ': ',
		 'textfieldtitelx' => '<input type="text" name="titelx' . $optionRow['options_id'] . '" ' .
		 'id="' . $optionRow['options_id'] . '" ' .
		 'size="50" ' .
		 'value="' . $optionRow['options_titel'] . '" />',
		 'textfieldnamex' => _('Textfield') . ': ',
		 'textfieldx' => '<textarea id="' . $optionRow['options_id'] .
		 '" rows="10" cols="45" ' .
		 'name="textx' . $optionRow['options_id'] . '">' .
		 $optionRow['options_text'] . '</textarea>',
		 'widthnamex' => _('Width') . ': ',
		 'widthx' => '<input type="text" name="widthx' . $optionRow['options_id'] . '" ' .
		 'id="widthx' . $optionRow['options_id'] . '" ' .
		 'size="5" ' .
		 'value="' . $optionRow['options_width'] . '" />',
		 'heightnamex' => _('Height') . ': ',
		 'heightx' => '<input type="text" name="heightx' . $optionRow['options_id'] . '" ' .
		 'id="heightx' . $optionRow['options_id'] . '" ' .
		 'size="5" ' .
		 'value="' . $optionRow['options_height'] . '" />',
		 'positionnamex' => _('Position') . ': ',
		 'positionx' => '<input type="text" name="positionx' . $optionRow['options_id'] . '" ' .
		 'id="positionx' . $optionRow['options_id'] . '" ' .
		 'size="5" ' .
		 'value="' . $optionRow['options_order'] . '" />',
		 'btn_delete' => '<a class="option_delete" href="index2.php?page=article&sub=attribute' .
		 '&id=' . $optionRow['options_attribute_id'] . '&func=options&optid=' .
		 $optionRow['options_id'] . '&subfunc=delete">' . _('Delete this option') . '</a>',
		 'btn_save' => '<input type="submit" name="submit" id="save" value="' .
		 _('Save changes') . '" />',
		 'texttitelHelp' => help('texttitel', 'article/option'),
		 'textfieldHelp' => help('textfield', 'article/option'),
		 'widthHelp' => help('width', 'article/option'),
		 'heightHelp' => help('height', 'article/option'),
		 'positionHelp' => help('position', 'article/option'));
	}

	/**
	 * create html-code for a dropdown-entry
	 * @param array $optionRow row from database. Table "options"
	 * @return array Associative array with html-code
	 */
	private function _getDropDown(&$optionRow)
	{
		$this->_htmlDropDown[] = array(
		 'dropdowntitelnamex' => _('Dropdowntitel') . ': ',
		 'dropdowntitelx' => '<input type="text" name="titelx' . $optionRow['options_id'] . '" ' .
		 'id="' . $optionRow['options_id'] . '" ' .
		 'size="' . $optionRow['options_width'] . '" ' .
		 'value="' . $optionRow['options_titel'] . '" />',
		 'widthnamex' => _('Width') . ': ',
		 'textfieldnamex' => _('Options') . ': ',
		 'textfieldx' => '<textarea class="ckeditor" id="' . $optionRow['options_id'] .
		 '" rows="15" cols="45" ' .
		 'name="textx' . $optionRow['options_id'] . '">' .
		 $optionRow['options_text'] . '</textarea>',
		 'widthx' => '<input type="text" name="widthx' . $optionRow['options_id'] . '" ' .
		 'id="widthx' . $optionRow['options_id'] . '" ' .
		 'size="5" ' .
		 'value="' . $optionRow['options_width'] . '" />',
		 'positionnamex' => _('Position') . ': ',
		 'positionx' => '<input type="text" name="positionx' . $optionRow['options_id'] . '" ' .
		 'id="positionx' . $optionRow['options_id'] . '" ' .
		 'size="5" ' .
		 'value="' . $optionRow['options_order'] . '" />',
		 'btn_delete' => '<a class="option_delete" href="index2.php?page=article&sub=attribute' .
		 '&id=' . $optionRow['options_attribute_id'] . '&func=options&optid=' .
		 $optionRow['options_id'] . '&subfunc=delete">' . _('Delete this option') . '</a>',
		 'btn_save' => '<input type="submit" name="submit" id="save" value="' .
		 _('Save changes') . '" />',
		 'texttitelHelp' => help('texttitel', 'article/option'),
		 'dropdownHelp' => help('dropdown', 'article/option'),
		 'widthHelp' => help('width', 'article/option'),
		 'heightHelp' => help('height', 'article/option'),
		 'positionHelp' => help('position', 'article/option'));
	}

	private function _getOptionList(&$optionRow)
	{
		$this->_htmlOptionList[] = array(
		 'optiontitelnamex' => _('Optiontitel') . ': ',
		 'optiontitelx' => '<input type="text" name="titelx' . $optionRow['options_id'] . '" ' .
		 'id="' . $optionRow['options_id'] . '" ' .
		 'size="' . $optionRow['options_width'] . '" ' .
		 'value="' . $optionRow['options_titel'] . '" />',
		 'widthnamex' => _('Width') . ': ',
		 'textfieldnamex' => _('Options') . ': ',
		 'textfieldx' => '<textarea class="ckeditor" id="' . $optionRow['options_id'] .
		 '" rows="15" cols="45" ' .
		 'name="textx' . $optionRow['options_id'] . '">' .
		 $optionRow['options_text'] . '</textarea>',
		 'widthx' => '<input type="text" name="widthx' . $optionRow['options_id'] . '" ' .
		 'id="widthx' . $optionRow['options_id'] . '" ' .
		 'size="5" ' .
		 'value="' . $optionRow['options_width'] . '" />',
		 'positionnamex' => _('Position') . ': ',
		 'positionx' => '<input type="text" name="positionx' . $optionRow['options_id'] . '" ' .
		 'id="positionx' . $optionRow['options_id'] . '" ' .
		 'size="5" ' .
		 'value="' . $optionRow['options_order'] . '" />',
		 'btn_delete' => '<a class="option_delete" href="index2.php?page=article&sub=attribute' .
		 '&id=' . $optionRow['options_attribute_id'] . '&func=options&optid=' .
		 $optionRow['options_id'] . '&subfunc=delete">' . _('Delete this option') . '</a>',
		 'btn_save' => '<input type="submit" name="submit" id="save" value="' .
		 _('Save changes') . '" />',
		 'texttitelHelp' => help('texttitel', 'article/option'),
		 'optionHelp' => help('option', 'article/option'),
		 'widthHelp' => help('width', 'article/option'),
		 'heightHelp' => help('height', 'article/option'),
		 'positionHelp' => help('position', 'article/option'));
	}

}

?>